package net.whg.stream;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SortedStream {

    public static void main(String[] args) {

        Student[] students = new Student[] {
                new Student("张三", 30),
                new Student("李四", 19),
                new Student("王五", 20),
                new Student("赵六", 21),
                new Student("钱七", 44),
                new Student("孙八", 23),
                new Student("周九", 24),
                new Student("吴十", 25),
                new Student("郑十一", 26),
                new Student("王十二", 27),
        };
        List<Student> list = Arrays.asList(students);
        list = list.stream().sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());
        list.forEach(student -> System.out.println(student.getName() + student.getAge()));

    }

    private static class Student {
        private String name;
        private int age;

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
